#!/bin/bash

#### README ####
#
# Test files naming convention:
# The xml files must end with with ".xml"
# The xml to validate with a DTD must begin with "rap"
#
################

OUTPUTDIR=out/
THEODIR=theo/
BINDIR=../bin/
BINNAME=analyseXML
DTDFILTER=*.dtd
XMLFILTER=*.xml
XMLVALFILTER=rap*
XMLERRFILTER=*err*
ERROUT=/dev/null

pass=0
fail=0

# Testing the presence of the binary file
ls $BINDIR/$BINNAME > /dev/null && echo "Exécutable trouvé" || echo -e '\E[01;31m'"\033[1mImpossible de trouver l'exécutable\E[0m\n"

## Testing simple XML parsing
echo "==== Testing XML parsing ===="
for f in `find . -name "$XMLFILTER" -not -name "$XMLERRFILTER"` 
do
	echo " === File: $f ==="
	#echo "$BINDIR/$BINNAME $f 2> $ERROUT"
	$BINDIR/$BINNAME < $f 2> $ERROUT && ((pass += 1)) || ((fail += 1))
	echo ''
done


## Testing invalid XML
echo "==== Testing XML validation ===="
for f in `find . -name "$XMLFILTER" -and -name "$XMLERRFILTER"` 
do
	echo " === File: $f ==="
	#echo "$BINDIR/$BINNAME $f 2> $ERROUT"
	$BINDIR/$BINNAME < $f 2> $ERROUT && ((fail += 1)) || ((pass += 1))
	echo ''
done


## Summary of the tests
echo -e "\n==== Summary ===="
echo -en '\E[01;32m'"\033[1mPass: $pass\E[0m"
echo -en " "
echo -en '\E[01;31m'"\033[1mFail: $fail\E[0m\n"

#for f in `ls $OUTPUTDIR` 
#do
#	echo "=== File: $f ==="
#	tail -n 1 $f
#	$BINDIR analyseDTD 
#done
